<?php

use console\db\Migration;
use yii\db\Expression;

/**
 * 格式化用户IP信息整数类型
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class m300000_000007_t_user_meta_format_ip extends Migration {

    /**
     * @inheritdoc
     */
    public $tableName = '{{%user_meta}}';

    /**
     * @inheritdoc
     */
    public function safeUp() {
        $column = 'temp_ip';
        //批量更新IP成整数类型
        $this->update($this->tableName, [
            'ip' => new Expression('INET_ATON(' . $column . ')'),
            $column => ''
        ], ['!=', $column, '']);
    }

}
